<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="图书名" width="180"> </el-table-column>
    <el-table-column prop="book.name" label="图书编号" width="180">
    </el-table-column>
    <el-table-column prop="book.author" label="图书作者" width="180">
    </el-table-column>
    <el-table-column prop="book.price" label="图书价格" width="180">
    </el-table-column>
    <el-table-column prop="data" label="借书日期"> </el-table-column>
    <el-table-column prop="forecastReturnData" label="预计归还日期">
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          bookName: "潘嘎之交",
          bookID: "999",
          bookAuthor: "嘎子",
          bookPrice: "￥399",
          borrowData: "2016-05-02",
          forecastReturnData: "2016-05-02"
        }
      ],
      msg: "",
      msg1: "",
      token: ""
    };
  },
  methods: {
    getUserBookInfo() {
      var token = localStorage.getItem("localStorage");
      this.$axios({
        method: "get",
        url: "http://127.0.0.1:8000/borrow/",
        data: {
          //这里是发送给后台的数据
          token: token
        }
      })
        .then(response => {
          var data = response.data;
        //   this.tableData = data;
        })
        .catch(error => {
          this.msg = msg;
          //如果token过期则重新获取token
          this.$axios({
            method: "get",
            url: "http://127.0.0.1:8000/token/refresh/",
            data: {
              //这里是发送给后台的数据
              token: token
            }
          })
            .then(response => {
              var data = response.data;
              localStorage.setItem("token", JSON.stringify(data.data.token));
            })
            .catch(error => {
              this.msg1 = msg1;
            });
        });
    }
  }
};
</script>

<style></style>
